package com.konne.nightmare.FastPublicOpinion.ui.information.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.view.WheelView;
import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpFragment;
import com.konne.nightmare.FastPublicOpinion.mvp.presenter.CGFreePresenter;
import com.konne.nightmare.FastPublicOpinion.mvp.view.ICGFreeView;
import com.konne.nightmare.FastPublicOpinion.ui.dialog.EditGroupNameDialog;
import com.konne.nightmare.FastPublicOpinion.ui.information.activity.CreateGroupActivity;
import com.konne.nightmare.FastPublicOpinion.utils.LoadProgressDialog;
import com.konne.nightmare.FastPublicOpinion.widget.CGLoadView;

import java.util.List;

import butterknife.BindView;

/**
 * Create by ws.
 * on Data:2022/1/25  Time:下午 1:21.
 * description: 创建学生自由分组 .
 */
public class CGFreeFargment extends BaseMvpFragment<ICGFreeView, CGFreePresenter> implements  ICGFreeView{
    @BindView(R.id.wv_time)
    WheelView wv_time;
    @BindView(R.id.tv_group_name)
    TextView tv_group_name;
    public static CGFreeFargment getInstance(){
        return new CGFreeFargment();
    }
    @Override
    protected CGFreePresenter createPresenter() {
        return new CGFreePresenter();
    }

    @Override
    public LoadProgressDialog getLoadDialog() {
        return dialog;
    }

    @Override
    public void cancelLoadDialog() {

    }

    @Override
    public int getLayout() {
        return R.layout.frag_cg_free;
    }

    @Override
    public void initView() {
        mPresenter.init();
        findViewById(R.id.iv_edit_name).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new EditGroupNameDialog(getContext()).setEditGroupNameListener(new EditGroupNameDialog.EditGroupNameListener() {
                    @Override
                    public void groupName(String txt) {
                        tv_group_name.setText(txt);
                    }
                }).show();
            }
        });
        findViewById(R.id.stv_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            mPresenter.submit();
            }
        });
    }

    @Override
    public void initWheelView(List<String> datas) {
        wv_time.setTextColorCenter(0xff3396FE);
        wv_time.setTextColorOut(0xff344854);
        wv_time.setDividerColor(Color.TRANSPARENT);
        wv_time.setGravity(Gravity.CENTER);
        wv_time.setLineSpacingMultiplier(2f);
        wv_time.setAdapter(new ArrayWheelAdapter(datas));
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public void load(int time, int maxTime) {
        ViewGroup ll_load=findViewById(R.id.ll_load);
        ll_load.setVisibility(View.VISIBLE);
        CGLoadView loadView=ll_load.findViewById(R.id.load_view);
        loadView.setMaxProgress(maxTime);
        loadView.setProgress(maxTime-time);
        TextView tv_load=ll_load.findViewById(R.id.tv_load);
        tv_load.setText(String.format("%ds后自动跳转到分组结果",time));
    }

    @Override
    public void loadEnd() {
        CreateGroupActivity.start(5);
        getActivity().finish();
    }
}
